package com.qisu.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 * @author alsan
 *
 */
@Component
public class CommandDispatcher {
	private Logger _log = LoggerFactory.getLogger(getClass());

	@Autowired private CommandList _repo;
	@Autowired private CommandUnknown _cmdUnknown;

	public Command dispatch(int cmd) {
		if(_repo.isInitialized()) {
			if(_repo.hasCommand(cmd)) {
				return _repo.getCommand(cmd); 
			}

			_log.warn("command " + cmd + " not found");
			return _cmdUnknown;
		} else {
			_log.error("command list not yet initialized");
			throw new IllegalArgumentException("command list not yet initialized");
		}
	}
}
